-function () {
    //设置canvas的宽高
    let canvas_width;
    let canvas_height;
    let random_points = [];
    let current_point = {
        x: null, //当前鼠标x
        y: null, //当前鼠标y
        max: 20000 // 圈半径的平方
    };

    function canvas() {
        //获取配置参数
        let config = {
            z: -1, //z-index
            o: 0.4, //opacity
            c: "0,0,0", //color
            n: 60, //count
            flush: 1000 / 60, //canvas最小刷新间隔
        };

        //创建画布，并添加到body中
        let the_canvas = document.createElement("canvas"); //画布
        let context = the_canvas.getContext("2d");
        the_canvas.style.cssText = "position:fixed;top:0;left:0;z-index:" + config.z + ";opacity:" + config.o;
        the_canvas.width = canvas_width;
        the_canvas.height = canvas_height;
        document.body.appendChild(the_canvas);

        //随机生成config.n条线位置信息
        for (let i = 0; i < config.n; i++) {
            // 随机点
            random_points.push({
                x: Math.random() * canvas_width, //随机位置
                y: Math.random() * canvas_height,
                xa: 2 * Math.random() - 1, //随机运动方向
                ya: 2 * Math.random() - 1,
                max: current_point.max //沾附距离
            });
        }
        let all_array = random_points.concat([current_point]);
        // 动画重绘
        let frame_func = window.requestAnimationFrame
            || window.webkitRequestAnimationFrame
            || window.mozRequestAnimationFrame
            || window.oRequestAnimationFrame
            || window.msRequestAnimationFrame
            || function (func) {
                window.setTimeout(func, config.flush);
            };

        //绘制过程函数
        function draw_canvas() {
            the_canvas.width = canvas_width;
            the_canvas.height = canvas_height;
            // 清空画布
            context.clearRect(0, 0, canvas_width, canvas_height);
            //随机的线条和当前位置联合数组
            let e, i, d, x_dist, y_dist, dist; //临时节点
            //遍历处理每一个点
            random_points.forEach(function (r, idx) {
                r.x += r.xa;
                r.y += r.ya; //移动
                r.xa *= r.x > canvas_width || r.x < 0 ? -1 : 1;
                r.ya *= r.y > canvas_height || r.y < 0 ? -1 : 1; //碰到边界，反向反弹
                context.fillRect(r.x - 0.5, r.y - 0.5, 1, 1); //绘制一个宽高为1的点
                //从下一个点开始
                for (i = idx + 1; i < all_array.length; i++) {
                    e = all_array[i];
                    // 当前点存在
                    if (null !== e.x && null !== e.y) {
                        x_dist = r.x - e.x; //x轴距离 l
                        y_dist = r.y - e.y; //y轴距离 n
                        dist = x_dist * x_dist + y_dist * y_dist; //总距离, m

                        if (dist < e.max) {
                            if (e === current_point && dist >= e.max / 2) {
                                r.x -= 0.03 * x_dist;
                                r.y -= 0.03 * y_dist; //靠近的时候加速
                            }
                            d = (e.max - dist) / e.max;
                            context.beginPath();
                            context.lineWidth = d / 2;
                            context.strokeStyle = "rgba(" + config.c + "," + (d + 0.2) + ")";
                            context.moveTo(r.x, r.y);
                            context.lineTo(e.x, e.y);
                            context.stroke();
                        }
                    }
                }
            });
        }

        let nowTime = 0,
            lastTime = Date.now();
        -function canvasLoop() {
            nowTime = Date.now();
            if (nowTime - lastTime > config.flush) {
                lastTime = nowTime;
                draw_canvas();
            }
            frame_func(canvasLoop);
        }();
    }


    function initFooterFunction() {
        //设置canvas的宽高
        canvas_width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
        canvas_height = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
        // let footer = document.querySelector("#footer");
        // console.log(document.body.scrollHeight);
        // console.log(canvas_height);
        // if (document.body.scrollHeight >= canvas_height) {
        //     footer.style.position = "relative";
        // } else {
        //     footer.style.position = "fixed";
        // }
       for (let r of random_points) {
            if (r.x > canvas_width || r.x < 0)
                r.x = Math.random() * canvas_width; //随机位置
            if (r.y > canvas_height || r.y < 0)
                r.y = Math.random() * canvas_height;
        }
    }

    let emptyFunction = (e) => {
    };
// window界面大小更改函数 - 更改footer的position
    let savedOnload = emptyFunction;
    if (typeof window.onload === "function")
        savedOnload = window.onload;
    window.onload = function (e) {
        initFooterFunction();
        // ================================若不需要动画效果注释该行即可====================================
        canvas();
        // ================================若不需要动画效果注释该行即可====================================
        savedOnload(e);
    };
// 当时鼠标位置存储，离开的时候，释放当前位置信息
    let savedOnmousemove = emptyFunction;
    if (typeof window.onmousemove === "function")
        savedOnmousemove = window.onmousemove;
    window.onmousemove = function (e) {
        savedOnmousemove(e);
        e = e || window.event;
        current_point.x = e.clientX;
        current_point.y = e.clientY;
    };

    let savedOnmouseout = emptyFunction;
    if (typeof window.onmouseout === "function")
        savedOnmouseout = window.onmouseout;
    window.onmouseout = function (e) {
        savedOnmouseout(e);
        current_point.x = null;
        current_point.y = null;
    };
// window界面大小更改函数 - 更改footer的position
    let savedOnresize = emptyFunction;
    if (typeof window.onresize === "function")
        savedOnresize = window.onresize;
    window.onresize = function (e) {
        initFooterFunction();
        savedOnresize(e);
    };
// 当前页面将被改变时触发此事件
    let savedOnunload = emptyFunction;
    if (typeof window.onunload === "function")
        savedOnunload = window.onunload;
    window.onunload = function (e) {
        initFooterFunction();
        savedOnunload(e);
    };
// 当前页面将被改变时触发此事件
    let onbeforeunload = emptyFunction;
    if (typeof window.onunload === "function")
        onbeforeunload = window.onunload;
    window.onunload = function (e) {
        initFooterFunction();
        onbeforeunload(e);
    };
}();



